#ifndef U8G2_GRAPH_H
#define U8G2_GRAPH_H

#include <Arduino.h>
#include "my_u8g2.h"

class U8G2_Graph
{
public:
  enum GraphType
  {
    LINE = 1,
    BAR,
  };
  U8G2_Graph(GraphType, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t min_val, uint16_t max_val);
  U8G2_Graph(GraphType, uint8_t x, uint8_t y, uint8_t w, uint8_t h, float min_val, float max_val);
  ~U8G2_Graph();

  void SetMinMaxHeight(uint8_t min_height, uint8_t max_height);
  void AddDataPoint(uint16_t val);
  void AddDataPoint(float val);
  void Show();
  void Reset();

private:
  GraphType type;
  uint8_t x;
  uint8_t y;
  uint8_t width;
  uint8_t height;

  // map
  uint8_t min_height;
  uint8_t max_height;
  uint16_t min_val_i;
  uint16_t max_val_i;
  float min_val_f;
  float max_val_f;

  uint8_t item_pixel_width;
  uint8_t item_pixel_width_gap = 0;

  uint8_t *item_buffer;
  uint8_t item_buffer_size;
  uint8_t buffer_count = 0;

  void init(GraphType, uint8_t x, uint8_t y, uint8_t w, uint8_t h);
  void addDataHeightPoint(uint8_t height);

  uint8_t map_val_to_height(uint16_t val, uint16_t min_val, uint16_t max_val);
  uint8_t map_val_to_height(float val, float min_val, float max_val);
};

#endif